﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wpf2.ViewModels;

namespace Wpf2.Models
{
    class thunghiem : PropertyChangedBase
    {

        private int _idCus;
        private string _phone;
        private string _cusName;
        private string _address;

        public string Address
        {
            get { return _address; }
            set { _address = value; OnPropertyChanged("Address"); }
        }

        public int IdCus
        {
            get { return _idCus; }
            set { _idCus = value; OnPropertyChanged("IdCus"); }
        }


        public string CusName
        {
            get { return _cusName; }
            set
            {
                var cus = WPFServices.Services.CustomersService.getCustomerByName(value);
                if (cus != null)
                {
                    if (MessageBox.Show("Lấy thông tin khách hàng này.", "Khách hàng đã tồn tại!", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                    {
                        _cusName = cus.NAME_CUS;
                        IdCus = cus.ID_CUS;
                        Phone = cus.PHONES;
                        Address = cus.ADDRESS;
                    }
                    else
                    {
                        _cusName = string.Empty;
                        IdCus = 0;
                        Phone = string.Empty;
                        Address = string.Empty;
                    }
                }
                else
                {
                    _cusName = value;
                    IdCus = 0;
                }
                OnPropertyChanged("CusName");
            }
        }

        public string Phone
        {
            get { return _phone; }
            set { _phone = value; OnPropertyChanged("Phone"); }
        }
    }
}
